<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>.: cPanel - <%=LG::ALBUM%> :.</title>
	<?php $this->import()?>
	<style type="text/css">
		.pic_options {
			position: absolute;
		}
		.pic_order {
			width: 30px;
		}
	</style>
	<script type="text/javascript">
		$(function() {
			$("img").error(function () {
				  $(this).unbind("error").attr("src", "<%=Properties::ALBUM_DIR%>/NO_PICTURE_IMAGE.png");
			});
			
			$('#ctrl_pics').css('display', '');
			$('#upload_pics').css('display', 'none');			
			
			$('#add_pics').click(function () {
				$('#ctrl_pics').css('display', 'none');
				$('#upload_pics').css('display', '');
				setTimeout(function() {
					$($('input[name="order[]"]')[0]).focus();
				}, 1);
			});
			
			$('#cancel_upload').click(function() {
				$('#ctrl_pics').css('display', '');
				$('#upload_pics').css('display', 'none');				
			});
			
			$('input[type="submit"]').click(function() {
				$('input[name="behavior"]').val($(this).attr('behavior'));
			});
		});
		
		function confirmDelete(name) {
			var msg = "<%=$MSG_CONFIRM%>";
			return confirm(msg.replace("<%=LG::VAL%>",name));
		}
	</script>
</head>
<body>
	<?php $this->header()?><br/>
		<table width="100%"><tr>
			<td align="left" width="50%"><a href="?c=album&a=grid"><%=LG::ALBUMS%></a> > <%=$album->name%></td>
			<td align="right" width="50%"><a id="add_pics" href="#upload_pics"><%=LG::ADD_IMAGES%></a></td>
		</tr></table>
		<hr/>
		<center><form action="" method="post" enctype="multipart/form-data">
			<input type="hidden" name="behavior"/>
			<table class="grid" cellspacing="1" cellpadding="5">
				<?php
					$i = 1;
					$isNextRow = true;
					foreach ($pics as $pic) {
						if ($isNextRow) {
							echo '<tr>';
							$isNextRow = false;
						}
						?>
						<td align="right" valign="bottom">
							<input type="hidden" name="picIDs[]" value="<%=$pic->id%>"/>
							<table class="pic_options">
								<tr>
									<td><input class="pic_order" name="orders[]" value="<%=$pic->order%>" maxlength="3"/></td>
									<td><input type="checkbox" name="delIDs[]" value="<%=$pic->id%>"/></td>
								</tr>
							</table>
							<img src="<%=$pic->thumb%>"/>
						</td>
						<?php
						if ($i % self::PICS_ITEMS == 0) {
							echo '</tr>';
							$isNextRow = true;
						}
						$i++;
					}
					if (sizeof($pics) % 5 != 0) {
						for ($i = 0; $i < 5 - (sizeof($pics) % 5); $i++) {
							echo '<td/>';
						}
						echo '</tr>';
					}
				?>
			</table>
			<?php if (sizeof($pics) > 0) { ?>
				<hr/>
				<div id="ctrl_pics">
					<input type="submit" behavior="update" value="<%=LG::F_UPDATE%>"/>
					<input type="submit" behavior="delete" value="<%=LG::F_DEL%>"/>
				</div>
			<?php } ?>
			<div id="upload_pics">
				<b><i><%=LG::ADD_5_PICS%></i></b>
				<table class="grid" cellspacing="1" cellpadding="5">
					<tr>
						<td><%=LG::G_ORDER%></td>
						<td><%=LG::G_IMG%></td>
					</tr>
					<?php for ($i = 1; $i < 6; $i++) {?>
						<tr>
							<td><input name="uploadOrders[]" maxlength="3" style="width: 30px;"/></td>
							<td><input name="imgs[]" type="file"/></td>
						</tr>
					<? } ?>
				</table>
				<hr/>
				<input type="submit" behavior="upload" value="<%=LG::F_SAVE%>"/>
				<input id="cancel_upload" type="button" value="<%=LG::F_CANCEL%>"/>
			</div>
		</form></center>
		<br/>
	<?php $this->footer()?>
</body>
</html>